package org.tis.tools.operatelog.module.log.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.tis.tools.core.utils.StringUtil;
import org.tis.tools.model.log.LogData;
import org.tis.tools.operatelog.module.log.dao.LogDataMapper;
import org.tis.tools.operatelog.module.log.exception.OperateLogException;
import org.tis.tools.operatelog.module.log.service.ILogDataService;


/**
 * logData的Service接口实现类
 * 
 * @author Auto Generate Tools
 * @date 2018/05/14
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class LogDataServiceImpl extends ServiceImpl<LogDataMapper, LogData> implements ILogDataService {

    @Autowired
    ILogDataService logDataService;

    @Override
    public Page<LogData> queryPageById(Page<LogData> page, Wrapper<LogData> wrapper) throws OperateLogException {

        Page<LogData> pageQue = new Page<>();

        if (null == wrapper.getEntity()){
            pageQue = selectPage(page);
        }else {
            LogData logData = wrapper.getEntity();

            Wrapper<LogData> wrapperQue = new EntityWrapper<LogData>();
            if (null != logData){
                wrapperQue.eq(LogData.COLUMN_GUID_OPERATE,logData.getGuidOperate());
            }

            pageQue = selectPage(page,wrapperQue);
        }

        return pageQue;
    }

    @Override
    public Page<LogData> queryByDataId(Page<LogData> page, Wrapper<LogData> entityWrapper) throws OperateLogException {

        Page<LogData> pageQue = new Page<>();

        if (null == entityWrapper.getEntity()){
            pageQue = selectPage(page);
        }else {
            LogData logData = entityWrapper.getEntity();

            entityWrapper = new EntityWrapper<>();

            if (StringUtil.isNotEmpty(logData.getGuid())){
                entityWrapper.eq(LogData.COLUMN_GUID,logData.getGuid());
            }
            if (StringUtil.isNotEmpty(logData.getGuidOperate())){
                entityWrapper.eq(LogData.COLUMN_GUID_OPERATE,logData.getGuidOperate());
            }
            if (null != logData.getOperateType()){
                entityWrapper.eq(LogData.COLUMN_OPERATE_TYPE,logData.getOperateType());
            }
            if (StringUtil.isNotEmpty(logData.getDataGuid())){
                entityWrapper.eq(LogData.COLUMN_DATA_GUID,logData.getDataGuid());
            }
            if (StringUtil.isNotEmpty(logData.getDataName())){
                entityWrapper.eq(LogData.COLUMN_DATA_NAME,logData.getDataName());
            }
            if (StringUtil.isNotEmpty(logData.getDataClass())){
                entityWrapper.eq(LogData.COLUMN_DATA_CLASS,logData.getDataClass());
            }
            if (StringUtil.isNotEmpty(logData.getDataString())){
                entityWrapper.eq(LogData.COLUMN_DATA_STRING,logData.getDataString());
            }

            pageQue = selectPage(page,entityWrapper);
        }

        return pageQue;
    }
}

